{template 'header', 'member'}
<div class="menus">
	<table cellpadding="0" cellspacing="0">
		<tr>
			<td class="tab_on" id="Tab0"><a href="service.php"><span>服务设置</span></a></td>
			<td class="tab_nav">&nbsp;</td>
		</tr>
	</table>
</div>
<form action="?">
<div class="ls">
	<table cellpadding="0" cellspacing="0" class="tb" style="font-size: 12px;">
		<tr>
			<th width="50">分类</th>
			<th>关联</th>
			<th width="50">添加</th>
		</tr>
		{loop $service_cats $k $v}
			<tr>
				<td class="tl apl" align="left">&nbsp;{$v[catname]}&nbsp;</td>
				<td class="apl tbl" id="vartype_{$k}" style="text-align: left">
					{loop $infos[$k] $v}
					<span>{$v[name]}<i data-serviceid="{$v[serviceid]}" data-brandid="{$v[brandid]}" data-modelid="{$v[modelid]}" data-styleid="{$v[styleid]}">[-]</i></span>
					{/loop}
				</td>
				<td class="button apl" data-serviceid="{$k}" style="cursor: pointer;height: auto">&nbsp;添加关联&nbsp;</td>
			</tr>
		{/loop}
	</table>
</div>
</form>
<div id="dialog-add-model" title="添加车款" style="display: none;">
	<table>
		<tr id="carcatTr">
			<th width="90"> <span class="cred">*</span> 车型类别</th>
			<td class="tr">
				<span id="carcatCtr">
					<select name="post[carcatid]" id="carcatid">
						<option value="0">请选择分类</option>
						{php cache_read('catetree-29.php');}
				</span>
				<span id="dcatid" class="cred"></span>
			</td>
		</tr>
		<tr id="brandTr" class="hideme">
			<th width="90"> <span class="cred">*</span> 汽车品牌</th>
			<td class="tr">
				<span id="brandCtr"></span>
				<span id="dbrandid" class="cred"></span>
			</td>
		</tr>
		<tr id="modelTr" class="hideme">
			<th width="90"> <span class="cred">*</span> 汽车车型</th>
			<td class="tr">
				<span id="modelCtr"></span>
				<span id="dmodelid" class="cred"></span>
			</td>
		</tr>
		<tr id="styleTr" class="hideme">
			<th width="90"> <span class="cred">*</span> 汽车车款</th>
			<td class="tr">
				<span id="styleCtr"></span>
				<span id="dstyleid" class="cred"></span>
			</td>
		</tr>
	</table>
	<p style="text-align: center;">
		<button id="button_add" onclick="addStyle();" style="width:100px;" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
			<span class="ui-button-text">添加关联</span>
		</button>
	</p>
</div>
<style type="text/css">
	.apl{
		line-height: 30px;
	}
	.tbl span{
		display: inline-block;
		padding-left: 15px;
	}
	.tbl span i{
		color:red;
		font-weight: bold;
		cursor: pointer;
	}
</style>
<script type="text/javascript">
	// delete
	$('.tbl i').on("click", function(event){
		var vars = $(this).attr('data-serviceid')+'|'+ $(this).attr('data-brandid')+'|'+$(this).attr('data-modelid')+'|'+$(this).attr('data-styleid');
		$.getJSON('service.php',{ajax:1,action:'del',vars:vars}, function(data){
			if(data.Error != 0) {
				alert('删除失败!');
				return false;
			} else {
				window.location.reload();
			}
		})
	});
	menuChanger('menu_web');
	s('service');
	$('.button').click(function(){
		$( "#dialog-add-model" ).dialog({
			width:500,
			draggable:false,
			modal: true
		});
		$('#button_add').attr('data-serviceid', $(event.target).attr('data-serviceid'));
	})
	function addStyle(){
		$this = $('#button_add');
		if ( $('#carcatid').val() ==0 ) {
			alert('车类别不能为空');
			return false;
		}
		if ( $('#brandid').val() ==0 ) {
			alert('品牌不能为空');
			return false;
		}
		var vars = $this.attr('data-serviceid')+'|'+ $('#carcatid').val()+'|'+$('#brandid').val()+'|'+$('#modelid').val()+'|'+$('#styleid').val();
		$.getJSON('service.php',{ajax:1,action:'add',val:vars}, function(data){
			if(data.Error != 0) {
				alert('添加失败!重复!');
				return false;
			} else {
				window.location.reload();
			}
		})

	}
</script>
{load('autoinfo.js')}
{template 'footer', 'member'}